﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.MenuaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.MenuaLL
{
    public class DelMenusCommandHandler : IRequestHandler<DelMenusCommand, ApiResult<int>>
    {
        IBaseReponsitory<Menus> Menus;

        public DelMenusCommandHandler(IBaseReponsitory<Menus> Menus)
        {
            this.Menus = Menus;
        }

        public async Task<ApiResult<int>> Handle(DelMenusCommand request, CancellationToken cancellationToken)
        {
            var list =await  Menus.GetQuery().Where(c => c.Menu_Id == request.Id).FirstOrDefaultAsync();
            list.Menu_IsDel = true;
            await Menus.UpdateAsync(list);
            return new ApiResult<int> 
            {
                Code=ApiEnum.Success,
                Message="删除成功",
                Data=1
            };
        }
    }
}
